package com.popcap.util;

import java.util.*;

/**
 * 
 * OrderedProperties
 * 
 * Description:
 * A property class with ability to get original order of properties
 * 
 * @author Evan Salomon evan.salomon@tko-software.com
 * 
 */
public class OrderedProperties extends Properties
{
    static final long serialVersionUID = 0;//NOTE: IF you want to serialize this you must fix me.
    
	private LinkedHashMap m_Properties = new LinkedHashMap();
	private boolean m_bModified = false;
	private Object[] m_PropertyNames;

	public Object put(Object strKey, Object value)
	{
		super.put(strKey, value);
		Object obj = m_Properties.get(strKey);
		if (m_Properties.containsKey(strKey))
		{
			m_Properties.remove(strKey);
		}
		m_Properties.put(strKey, value);
		m_bModified = true;
		return obj;
	}

	public String getPropertyKey(int nIndex)
	{
		if (m_bModified)
		{
			m_bModified = false;
			m_PropertyNames = m_Properties.keySet().toArray();
		}
		return (String)m_PropertyNames[nIndex];
	}
}